package com.jshan.blog.base.admin.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.jshan.blog.valid.AddGroupValid;
import com.jshan.blog.valid.UpdateGroupValid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 系统用户表
 *
 * @author jshan
 * @TableName sys_user
 */
@TableName(value = "sys_user")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysUser implements Serializable {
    /**
     * id
     */
    @TableId(type = IdType.AUTO)
    @NotNull(message = "用户 id 不能为空", groups = {UpdateGroupValid.class})
    private Integer id;

    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空", groups = {AddGroupValid.class, UpdateGroupValid.class})
    private String username;

    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空", groups = {AddGroupValid.class, UpdateGroupValid.class})
    private String pwd;

    /**
     * 手机号
     */
    @Pattern(regexp = "0?(13|14|15|18|17)[0-9]{9}",
            message = "手机号码格式不正确",
            groups = {AddGroupValid.class})
    private String phone;

    /**
     * 昵称
     */
    private String nickname;

    /**
     * 性别(0 未知 1 男 2 女)
     */
    private Integer sex;

    /**
     * 生日
     */
    // @JsonDeserialize(using = LocalDateDeserializer.class)
    // @JsonSerialize(using = LocalDateSerializer.class)
    // @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    // @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate birthday;


    /**
     * 头像地址
     */
    private String logo;

    /**
     * 年龄，--废弃，以生日为主
     */
    private Integer age;

    /**
     * 身份证
     */
    private String idCard;

    /**
     * 邮箱地址
     */
    @Pattern(regexp = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}",
            message = "邮箱格式不正确",
            groups = {AddGroupValid.class})
    private String email;

    /**
     * 账户状态 (如 冻结；禁言；正常。 关联字典表account_status)
     */
    private Integer accountStatusCd;

    /**
     * 标签（自定义关联到字典表）
     */
    private Integer userTagCd;

    /**
     * 最近一次登录时间
     */
    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    // @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    // @JsonSerialize(using = LocalDateTimeSerializer.class)
    // @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastLoginTime;

    /**
     * 创建时间
     */
    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    // @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    // @JsonSerialize(using = LocalDateTimeSerializer.class)
    // @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */

    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    // @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    // @JsonSerialize(using = LocalDateTimeSerializer.class)
    // @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 是否删除(0未删除，1 删除)
     */
    @TableLogic
    private Integer delFlag;

    /**
     *
     */
    private Integer createId;

    /**
     *
     */
    private Integer updateId;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}
